package com.lanou.musicproject.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.lanou.musicproject.R;
import com.lanou.musicproject.bean.SingerInfo;
import com.lanou.musicproject.utils.MyConfig;
import com.lanou.musicproject.volley.VolleySingleton;

import org.json.JSONObject;

import java.util.List;

/**
 * Created by dllo on 15/10/24.
 * 搜索歌手具体信息
 */
public class SeekSingerInfoFragment extends Fragment {
    private TextView name, country, area, nation, brithPlace, school, earlyExperience, entertainmentExperience, awards;
    private VolleySingleton volleySingleton;
    private SingerInfo.DataEntity data;
    private String url;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.seeksingerinfo_fragment, null);
        volleySingleton = VolleySingleton.getInstance(getActivity());
        name = (TextView) view.findViewById(R.id.name);
        country = (TextView) view.findViewById(R.id.country);
        area = (TextView) view.findViewById(R.id.area);
        nation = (TextView) view.findViewById(R.id.nation);
        brithPlace = (TextView) view.findViewById(R.id.brithPlace);
        school = (TextView) view.findViewById(R.id.school);
        earlyExperience = (TextView) view.findViewById(R.id.earlyExperience);
        entertainmentExperience = (TextView) view.findViewById(R.id. entertainmentExperience);
        awards = (TextView) view.findViewById(R.id.awards);
        initData();
        return view;
    }

    private void initData() {
        int _id = MyConfig.getSharePreInt(getActivity(), "entiey", "_id");
        url = "http://api.dongting.com/song/singer/" +
                _id +
                "?utdid=VSeGyjss0fEDAOqIktP5W%2BO4&detail=true";
        JsonObjectRequest jr = new JsonObjectRequest(url, null, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                  String str = response.toString();
                SingerInfo info = JSON.parseObject(str, SingerInfo.class);
                   data =  info.getData();
                info();

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });
 volleySingleton.addQueue(jr);

    }

    private void info() {
        name.setText(data.getName());
        country.setText(data.getCountry());
        area.setText(data.getArea());
        nation.setText(data.getNation());
        brithPlace.setText(data.getBirthPlace());
        school.setText(data.getSchool());
        earlyExperience.setText(data.getEarlyExperience());
        entertainmentExperience.setText(data.getEntertainmentExperience());
        awards.setText(data.getAwards());
    }


}
